package com.zhang.network.network;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.network.mapper.FriendMapper;
import com.zhang.network.mapper.UserMapper;
import com.zhang.network.model.Friend;
import com.zhang.network.model.User;
import com.zhang.network.model.recommend.RecommendDTO;
import com.zhang.network.model.recommend.RecommendVO;
import com.zhang.network.service.RecommendService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Random;

/**
 * @author: zhangshuaiyin
 * @date: 2021/4/10 11:57
 */
@SpringBootTest
@Slf4j
public class UserData {

    @Resource
    UserMapper mapper;

    @Resource
    FriendMapper friendMapper;

    @Resource
    RecommendService recommendService;

    @Test
    public void getFriendRequest() {
        RecommendDTO recommendDTO = new RecommendDTO();
        recommendDTO.setUserId(1);
        recommendDTO.setPageNum(1);
        recommendDTO.setPageSize(5);
        Page<RecommendVO> page = recommendService.pageFriendRequest(recommendDTO);
        log.info("好友请求列表");
        log.info(page.getRecords().toString());
        log.info(String.valueOf(page));
    }

    @Test
    public void getRecommend() {
        RecommendDTO recommendDTO = new RecommendDTO();
        recommendDTO.setUserId(1);
        recommendDTO.setPageNum(1);
        recommendDTO.setPageSize(5);
        Page<RecommendVO> page = recommendService.pageRecommend(recommendDTO);
        log.info("推荐列表");
        log.info(page.getRecords().toString());
        log.info(page.getRecords().get(0).getNickName());
    }

    @Test
    public void getTest() {
        int t = friendMapper.sameFriendNum(1,14);
        log.info("共同好友");
        log.info(t+"");

    }

    @Test
    public void addUser() {
        for (int i = 1; i < 13; i++) {
            User obj = new User(null, i + "0001", "123456", "张三" + i, "zhangsan" + i,
                    1 % i, "Java", LocalDate.of(2021, 3, 1), "1383838383" + i,
                    "zhangsan" + i + "@qq.com", null, null, "广东省","深圳市",1 ,
                    1);
            mapper.insert(obj);
        }
    }

    @Test
    public void test() {
        Random random = new Random();
        long account = random.nextInt(10000) + System.currentTimeMillis();
        User user = new User();
        user.setAccount(account+"");
        log.info(user.getAccount());
    }

    @Test
    public void addFriend() {
        int userId = 14;
        for (int i = 11; i < 19; i++) {
            if (i != userId) {
                Friend obj = new Friend();
                obj.setUserId(userId);
                obj.setFriendId(i);
                friendMapper.insert(obj);
            }
        }
    }

    @Test
    public void removeFriend() {
        int userId = 1;
        Friend obj = new Friend();
        obj.setUserId(userId);
        obj.setFriendId(11);
        friendMapper.insert(obj);

    }
}
